package com.qsl.ssyx.product.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.model.product.SkuInfo;
import com.qsl.ssyx.product.service.CategoryService;
import com.qsl.ssyx.product.service.SkuInfoService;
import com.qsl.ssyx.vo.product.CategoryQueryVo;
import com.qsl.ssyx.vo.product.SkuInfoQueryVo;
import com.qsl.ssyx.vo.product.SkuInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * sku信息 前端控制器
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-10
 */
@Api(tags = "sku列表接口")
@RestController
@RequestMapping("/admin/product/skuInfo")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    @ApiOperation("条件分页查询")
    @GetMapping("{page}/{limit}")
    public Result selectPage(@ApiParam(value = "当前页") @PathVariable Integer page
            , @ApiParam(value = "每页记录数") @PathVariable Integer limit
            , SkuInfoQueryVo skuInfoQueryVo) {
        Page<SkuInfo> pageParam = new Page<>(page, limit);
        IPage<SkuInfo> model = skuInfoService.selectPage(pageParam, skuInfoQueryVo);
        return Result.ok(model);
    }

    @ApiOperation("新增") // sku_info,sku_attr_value,sku_image,sku_poster
    @PostMapping("save")
    public Result save(@RequestBody SkuInfoVo skuInfoVo) {
        boolean flag = skuInfoService.saveSkuInfo(skuInfoVo);
        System.out.println("===>"+skuInfoVo);
        return Result.ok(flag);
    }

    @ApiOperation("根据Id查询") //  sku_info,sku_attr_value,sku_image,sku_poster
    @GetMapping("getById/{id}")
    public Result save(@ApiParam(value = "skuId") @PathVariable("id") Integer Id) {
        SkuInfoVo skuInfo = skuInfoService.getBySkuId(Id);
        return Result.ok(skuInfo);
    }

    @ApiOperation("修改") // sku_info,sku_attr_value,sku_image,sku_poster
    @PutMapping("update")
    public Result update(@RequestBody SkuInfoVo skuInfovo) {
        boolean flag = skuInfoService.updateBySkuId(skuInfovo);
        return Result.ok(flag);
    }

    @ApiOperation("删除") // sku_info,sku_attr_value,sku_image,sku_poster
    @DeleteMapping("remove/{Id}")
    public Result remove(@PathVariable Integer Id) {
        boolean flag = skuInfoService.removeBySkuId(Id);
        return Result.ok(flag);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Integer> idList) {
        boolean flag = skuInfoService.removeBySkuIds(idList);
        return Result.ok(idList);
    }

    // ===================
    @ApiOperation("商品上、下架状态")  // 上架状态：0->下架；1->上架
    @GetMapping("publish/{id}/{status}")
    public Result updatePublishStatus(@ApiParam(value = "商品id", required = true) @PathVariable Long id,
                                      @ApiParam(value = "上、下架状态", required = true) @PathVariable("status") Integer publishStatus) {
        boolean flag = skuInfoService.updatePublishStatus(id, publishStatus);
        return Result.ok(flag);
    }

    @ApiOperation("商品审核状态") // 审核状态：0->未审核；1->审核通过
    @GetMapping("check/{id}/{status}")
    public Result check(@ApiParam(value = "商品id", required = true) @PathVariable Long id,
                        @ApiParam(value = "商品审核状态", required = true) @PathVariable Integer status) {
        boolean flag = skuInfoService.updateCheckStatus(id, status);
        return Result.ok(flag);
    }

    @ApiOperation("是否新人专享") // 0->否；1->是
    @GetMapping("isNewPerson/{id}/{status}")
    public Result isNewPerson(@ApiParam(value = "商品id", required = true) @PathVariable Long id,
                              @ApiParam(value = "是否新人专享", required = true) @PathVariable("status") Integer isNewPerson) {
        boolean flag = skuInfoService.isNewPerson(id, isNewPerson);
        return Result.ok(flag);
    }
}

